home *** CD-ROM | disk | FTP | other *** search
-
-
- /*Size of the array*/
- #define kArraySizeH 15
- #define kArraySizeV 12
-
- /*Size of the tiles*/
- #define kTileSizeH 32
- #define kTileSizeV 32
-
- /*The world is accessed through a Handle to a 'TEXT' resource:*/
- Handle gWorldHandle;
-
- /*…and this is the resource number:*/
- #define kWorldResource 128
-
- /* Pictures*/
- PicHandle floorTile;
- PicHandle playerTile;
- PicHandle enemyTile;
- PicHandle goldTile;
- PicHandle wallTile;
- PicHandle exitTile;
-
- /* Draw a tile */
-
- static void DrawTile(short h, short v)
- {
- Rect tileRectangle;
- char theTile;
-
- SetRect(&tileRectangle, h * kTileSizeH, v * kTileSizeV, (h + 1) * kTileSizeH, (v + 1) * kTileSizeV);
-
- theTile = *(*gWorldHandle + h + v * (kArraySizeH+1));
-
- switch (theTile)
- {
- case ' ':
- DrawPicture(floorTile, &tileRectangle); break;
- case '#':
- DrawPicture(wallTile, &tileRectangle); break;
- case '@':
- DrawPicture(playerTile, &tileRectangle); break;
- case '*':
- DrawPicture(enemyTile, &tileRectangle); break;
- case '$':
- DrawPicture(goldTile, &tileRectangle); break;
- case 'X':
- DrawPicture(exitTile, &tileRectangle); break;
- default:
- PaintRect(&tileRectangle);
- }
- } /*DrawTile*/
-
-
- /* Standard inits */
-
- static void InitToolbox(void) {
- InitGraf (&qd.thePort);
- InitFonts ();
- FlushEvents (everyEvent,0);
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (nil);
- InitCursor ();
- }
-
-
- /****************** Main program ******************/
-
- void main(void) {
- WindowPtr myWindow;
- Rect windowRectangle;
- short h,v;
-
- InitToolbox();
-
- /*Set up the window*/
- SetRect(&windowRectangle, 50, 50, 50 + kArraySizeH * kTileSizeH, 50 + kArraySizeV * kTileSizeV);
- myWindow = NewCWindow(nil, &windowRectangle, "\pText grid demo", true, 0, (WindowPtr)-1L, false, 0);
- SetPort(myWindow);
-
- /*Load all pictures*/
- floorTile = GetPicture(128); /*PICT resource #128.*/
- playerTile = GetPicture(129); /*PICT resource #129.*/
- enemyTile = GetPicture(130); /*PICT resource #130.*/
- goldTile = GetPicture(131); /*PICT resource #131.*/
- wallTile = GetPicture(132); /*PICT resource #132.*/
- exitTile = GetPicture(133); /*PICT resource #133.*/
-
- /*Get the resource*/
- gWorldHandle = GetResource('TEXT', kWorldResource);
- if (gWorldHandle == nil) /*Error! In a real program, you should check the picts above as well.*/
- {
- SysBeep(1);
- ExitToShell();
- }
-
- /*Draw all tiles!*/
- for ( h = 0 ; h < kArraySizeH ; h++)
- for ( v = 0 ; v < kArraySizeV ; v++)
- DrawTile(h, v);
-
- while ( ! Button () )
- ;
- } /*TextGrid*/
-